<?php
/**
 *  Global state 
 */

class QStone_Context {
    private static $instance;
    private $resources;

    private function __construct() {
        $this->resources = array();
    }

    private function __clone(){}

    function __get($resource) {
        if(!isset($this->resources[$resource])){
            return '20110805';
        }
        return $this->resources[$resource];
    }

    function __set($resource,$value){
        $this->resources[$resource] = $value;
    }

    public static function getInstance(){
        if( ! isset(self::$instance)){
            self::$instance = new self();
        }
        return self::$instance;
    }
    
    /**
     *    Static check for running in the comand line.
     *    @return boolean        True if CLI.
     *    @access public
     */
    public static function inCli(){
        return php_sapi_name() == 'cli';
    }

    /**
     *    Test to see if a class is a test 
     *    @param string $class     Class name.
     *    @access public
     */
    public static function isTest($class) {
        $testclass = new ReflectionClass($class);
        return (is_subClass_of($class,"Test") && (!$testclass->isAbstract()));
    }

    /**
     *    Test to see if a class is a testsuite 
     *    @param string $class     Class name.
     *    @access public
     */
    public static function isTestSuite($class){
        while($class = get_parent_class($class)){
            $class = strtolower($class);
            if($class == "test_suite"){
                return true;
            }
        }
        return false;
    }
}

?>
